package com.usian.wemedia.controller;

import com.usian.apis.wemedia.LoginControllerApi;
import com.usian.model.base.BaseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmUserDto;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.MediaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements BaseResult , LoginControllerApi {

    @Autowired
    private MediaUserService userService;

    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser){
        return userService.saveMediaUser(wmUser);
    }

    @PostMapping("update/authorId")
    public ResponseResult updateAuthorId(@RequestBody WmUser user){
        if (user == null || user.getId() == null)return paramError;
        boolean b = userService.updateById(user);
        return success(b);
    }

    @Autowired
    private LoginControllerApi wmUserService;

    @PostMapping("/in")
    @Override
    public ResponseResult login(@RequestBody WmUserDto dto){
        return wmUserService.login(dto);
    }
}
